package com.dzm.xgb.core.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dzm.common.result.R;
import com.dzm.xgb.core.pojo.entity.Borrower;
import com.dzm.xgb.core.pojo.vo.BorrowerApprovalVO;
import com.dzm.xgb.core.pojo.vo.BorrowerDetailVO;
import com.dzm.xgb.core.pojo.vo.BorrowerSearchVo;
import com.dzm.xgb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：Dzm
 * 时间：2024-09-20-10:00
 * 功能：
 */

@RestController
@Api(tags = "借款人管理")
@RequestMapping("/admin/core/borrower")
public class AdminBorrowerController {

    @Autowired
    private BorrowerService borrowerService;

    @ApiOperation("借款人查询")
    @PostMapping("/search/{pageNum}/{pageSize}")
    public R search(@PathVariable("pageNum") Integer pageNum,
                    @PathVariable("pageSize")Integer pageSize,
                    @RequestParam(value = "keyWords", required = false) String keyWords) {
        Page<Borrower> pageModel = borrowerService.search(pageNum, pageSize, keyWords);

        return R.ok().data("pageModel", pageModel);
    }

    @ApiOperation("查询借款人详细信息")
    @GetMapping("/show/{id}")
    public R show(@PathVariable("id") Long id) {
        BorrowerDetailVO detailVO = borrowerService.getDetailVo(id);

        return R.ok().data("detail", detailVO);
    }

    @ApiOperation("借款人信息审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO vo) {
        borrowerService.approval(vo);

        return R.ok().message("审批完成！");
    }

}
